﻿using System;
using System.Collections;
using System.Collections.Generic;


namespace FireBus.Contracts
{
	public class ExtensionResponseCollection<TResponse> :
		IEnumerable<KeyValuePair<ExtensionName, TResponse>>
		where TResponse : class
	{
		private readonly IDictionary<ExtensionName, TResponse> _Items
			= new Dictionary<ExtensionName, TResponse>();
		
		public Int32 Count
		{
			get { return _Items.Count; }
		}

		public TResponse First
		{
			get
			{
				var enumerator = _Items.GetEnumerator();
				if (enumerator.MoveNext())
				{
					return enumerator.Current.Value;
				}
				return null;
			}
		}

		public TResponse Get(ExtensionName extension)
		{
			return _Items[extension];
		}

		public void Add(ExtensionName extension, TResponse response)
		{
			_Items.Add(extension, response);
		}

		public IEnumerator<KeyValuePair<ExtensionName, TResponse>> GetEnumerator()
		{
			return _Items.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
}
